"""Simple wrapper for standard checkout as implemented in payment.views"""
from django import http
from django.views.decorators.cache import never_cache
from django.template import Context, loader, RequestContext
from livesettings import config_get_group
from payment.views import confirm, payship
from satchmo_utils.dynamic import lookup_url
from ocms.merch.owasp_payments.forms import OwaspPaymentsPayShipForm
import logging
    
settings = config_get_group('PAYMENT_OWASP_PAYMENTS')

log = logging.getLogger('OWASP_PAYMENTS.views')

   
def pay_ship_info(request):
    return payship.base_pay_ship_info(
        request, 
        settings, 
        owasp_payments_process_form, 
        'shop/checkout/owasppayments/pay_ship.html')

     
def confirm_info(request):
    return confirm.credit_confirm_info(
        request, 
        settings, 
        template='shop/checkout/owasppayments/confirm.html')
    
def owasp_payments_process_form(request, contact, working_cart, payment_module):
    log.debug('owasp_payment__process_form')
    if request.method == "POST":
        log.debug('handling POST')
        new_data = request.POST.copy()
        form =  OwaspPaymentsPayShipForm(request, payment_module, new_data)
        if form.is_valid():
            form.save(request, working_cart, contact, payment_module)
            url = lookup_url(payment_module, 'satchmo_checkout-step3')
            return (True, http.HttpResponseRedirect(url))
    else:
        log.debug('new form')
        form =  OwaspPaymentsPayShipForm(request, payment_module)

    return (False, form)